<template>
	<view>
		时间：{{ hour }}:{{ minute }}:{{ second }}
	</view>
</template>

<script>
export default {
	name: '',
	data() {
		return {
			hour: '',
			minute:'',
			second: ''
		};
	},
	onLoad(e) {
		console.log('前页面传过来的数据------', e);
		this.getTime()
	},
	methods: {
		// 获取时间
		getTime() {
			var now = new Date();
			var year = now.getFullYear(); //得到年份
			var month = now.getMonth() + 1; //得到月份
			var date = now.getDate(); //得到日期
			if (now.getHours() < 10) {
				this.hour = '0' + now.getHours(); //得到小时数
			} else {
				this.hour = now.getHours(); //得到小时数
			}
			if (now.getMinutes() < 10) {
				this.minute = '0' + now.getMinutes(); //得到小时数
			} else {
				this.minute = now.getMinutes(); //得到小时数
			}
			if (now.getSeconds() < 10) {
				this.second = '0' + now.getSeconds(); //得到小时数
			} else {
				this.second = now.getSeconds(); //得到小时数
			}
			let that = this;
			setTimeout(() => {
				that.getTime();
			}, 1000); //定时器一直调用show()函数
			return;
		},
	}
};
</script>

<style lang="scss" scoped></style>
